#ifndef ALTTILEDMAP_H
#define ALTTILEDMAP_H

#include "altmap.h"
#include "alttileset.h"

namespace Alt {
     /*! Describes a tile's properties. */
     struct Tile {
          /*! The material assigned to this tile. */
          int material;

          /*! \see Tileset::tileRect */
          int tileNumber;
     };


     /*! Saves a tile to a stream.
          \param stream The stream to save into.
          \param tile The tile to save. */
     QDataStream& operator << (QDataStream& stream, const Tile& tile);

     /*! Loads a tile from a stream.
          \param stream The stream to load from.
          \param tile The tile to load. */
     QDataStream& operator >> (QDataStream& stream, Tile& tile);

     /*! A list of tiles. */
     typedef QList<Tile> TileList;

     /*! A 2-dimensional list of tiles. */
     typedef QList<TileList> Tile2DList;

     /*! Provides a simple tiled map. A tiled map consists of a tileset (which contains the tile graphics),
          and rows of TileGraphicItems. */
     class TiledMap : public Map {
     public:
          /*! Default constructor.
               \param item The map's parent. */
          TiledMap(QGraphicsItem* item = 0);

          QRectF boundingRect() const;

          bool load(QDataStream& stream);

          QString mapType() const;

          int material(const QPointF& pos) const;

          void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);

          Projection projection() const;

          bool save(QDataStream& stream) const;

          /*! Sets the map's tileset.
               \param tileset The new tileset. */
          void setTileset(const Tileset& tileset);

          /*! The map's tileset. */
          const Tileset& tileset() const;

          int type() const;

     private:
          /*! The map's tiles. */
          Tile2DList m_tiles;

          /*! The map's tileset. */
          Tileset m_tileset;
     };
}

Q_DECLARE_TYPEINFO(Alt::Tile, Q_PRIMITIVE_TYPE);

#endif
